package mumethod;

import java.util.List;

import muobject.Question;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

public class QuestionReportDataSource implements JRDataSource{
	private List<Question> datas = null ;
	private int loop = -1 ; 
	
	public QuestionReportDataSource(List<Question> data){
		this.datas = data;
	}
	
	public Object getFieldValue(JRField field) throws JRException {
		Question temp = (Question)this.datas.get(loop);
		Object rs = "" ;
		if("qno".equals(field.getName())){  
			rs = temp.getQno();   
		}else if("years".equals(field.getName())){
			rs = temp.getYears();
		}else if("content".equals(field.getName())){
			rs = temp.getContent();
		}else if("type".equals(field.getName())){
			rs = temp.getType();
		}
		
		temp = null ;  
		return rs;
	}
	
	public boolean next() throws JRException {
		loop ++ ;
		if(loop >= datas.size()){
			return false;
		}
		else{   
			return true ;
		}
	}
	
	public void finalized(){
		datas = null ;  
	}
}
